<template>
	<view>
		<view class="userinfo">
			<image src="/static/ulogo.jpg" />
		</view>
		<view class="container">
			<form>
				<view class="user-item">
					<view class="uni-form-item uni-column">
						<text>用户名：</text><input v-model="user.uname" type="text">
					</view>
					<view class="uni-form-item uni-column">
						<text>密码：</text><input v-model="user.upwd" type="text" password="true">
					</view>
					<view class="btopt">
						<button type="warn" @click="login()">登录</button>
						<button type="warn" @click="test()">test</button>
						<navigator url="../register/register">前往注册</navigator>
					</view>

				</view>
			</form>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					uname: "",
					upwd: ''
				}
			}
		},
		methods: {
			login() {
				this.$request({
					url: '/user/login',
					method: 'post',
					data: this.user,
					success: (res) => {
						let token = res.data;
						uni.setStorageSync("token",token);
						uni.showToast({
							title: '登录成功',
							success: () => {
								// setTimeout(function() {
								// 	uni.switchTab({url: '../index/index'})
								// }, 2000)
							}
						})
					}
				})
			},
			test(){
				let token = uni.getStorageSync("token");
				this.$request({
					url:'/user/session/'+token,
					success:(res)=>{
						console.log(res);
					}
				})
			}
		}
	}
</script>

<style>
	page {
		background: #F8F8FF;
	}

	.userinfo {
		background-color: #d81e06;
		height: 350rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		border-radius: 0 0 200rpx 200rpx/0 0 80rpx 80rpx;
		padding-bottom: 50rpx;
	}

	.userinfo image {
		width: 140rpx;
		height: 140rpx;
		border-radius: 100rpx;
		margin: 0 auto;
		display: block;
	}

	.userinfo text {
		color: white;
		line-height: 60rpx;
		font-size: 32rpx;
		margin-top: 24rpx;
		text-align: center;
	}

	.container {
		margin: 16rpx;
		position: relative;
		top: -100rpx;
	}

	.user-item {
		background-color: white;
		border-radius: 16rpx;
		box-shadow: 0 4rpx 4rpx #F8F8FF;
		padding: 100rpx 50rpx;
		margin-bottom: 50rpx;


	}

	.uni-form-item {
		margin: 48rpx 10rpx;
		display: flex;
		flex-direction: row;
	}

	.uni-form-item text {
		line-height: 60rpx;
		width: 150rpx;
	}

	.uni-form-item input {
		flex: 1;
		border: 1px solid #ccc;
		border-radius: 8rpx;
		height: 52rpx;
		line-height: 52rpx;
		padding-left: 20rpx;
	}

	button {
		margin-bottom: 60rpx;
		margin-top: 60rpx;
	}

	.btopt {
		text-align: center;
	}
</style>